Page({
  data: {
    currentWeek: 1,
    weekRange: Array.from({length: 20}, (_, i) => `第${i + 1}周`),
    weekdays: ['周一', '周二', '周三', '周四', '周五'],
    timeSlots: [
      { start: '8:00', end: '9:40' },
      { start: '10:00', end: '11:40' },
      { start: '14:00', end: '15:40' },
      { start: '16:00', end: '17:40' },
      { start: '19:00', end: '20:40' }
    ],
    courses: [] // 这里将存储课程数据
  },

  onLoad: function() {
    this.loadCourses();
  },

  loadCourses: function() {
    // 这里添加从后端获取课程数据的逻辑
  },

  onWeekChange: function(e) {
    this.setData({
      currentWeek: Number(e.detail.value) + 1
    });
    this.loadCourses();
  },

  hasCourse: function(timeIndex, dayIndex) {
    // 检查指定时间和日期是否有课程
    return this.getCourse(timeIndex, dayIndex) !== null;
  },

  getCourse: function(timeIndex, dayIndex) {
    // 获取指定时间和日期的课程信息
    return this.data.courses.find(course => 
      course.timeIndex === timeIndex && 
      course.dayIndex === dayIndex &&
      course.week === this.data.currentWeek
    );
  },

  showCourseDetail: function(e) {
    const { time, day } = e.currentTarget.dataset;
    const course = this.getCourse(time, day);
    if (course) {
      wx.showModal({
        title: course.name,
        content: `教室：${course.location}\n教师：${course.teacher}`,
        showCancel: false
      });
    }
  },

  showAddCourse: function() {
    wx.navigateTo({
      url: '/pages/addCourse/addCourse'
    });
  }
});